package com.kinyx.framework.db.sentence.str.demo.insert;

import org.junit.Assert;
import org.junit.Test;

import com.kinyx.framework.db.sentence.str.INSERT;
import com.kinyx.framework.db.sentence.str.SQLBuilder;

public class INSERT_Tester {

	final INSERT insert = SQLBuilder.insert("T_DEMO");

	String defaultSentenceSQL = "INSERT INTO T_DEMO";

	protected void test(final INSERT insert, final String expectedSentence, final String expectedString) {
		Assert.assertEquals(expectedSentence, insert.getSentence());
		Assert.assertEquals(expectedString, insert.toString());
	}

	String defaultStringSQL = "SQL: [" + this.defaultSentenceSQL + "], params: []";

	@Test
	public void test0() {
		this.test(this.insert, this.defaultSentenceSQL, this.defaultStringSQL);
	}

	@Test
	public void demo1() {
		final String sentence = "INSERT INTO T_DEMO (ID) VALUES (?)";
		final String str = "SQL: [" + sentence + "], params: [foo]";
		this.test(//
				SQLBuilder.insert("T_DEMO")//
						.values("ID", "foo")//
				, sentence, str);
	}

	@Test
	public void test_values1() {
		final String sentence = this.defaultSentenceSQL + " (ID) VALUES (?)";
		final String str = "SQL: [" + sentence + "], params: [foo]";
		this.test(this.insert.values("ID", "foo"), sentence, str);
	}

	@Test
	public void test_values2() {
		final String sentence = this.defaultSentenceSQL + " (ID, USING_STATUS) VALUES (?, ?)";
		final String str = "SQL: [" + sentence + "], params: [foo, bar]";
		this.test(this.insert.values("ID", "foo").values("USING_STATUS", "bar"), sentence, str);
	}

}
